import json

import requests
import hashlib

username = 'yh'
password = '123456'
md5 = hashlib.md5(password.encode())  # 创建MD5对象
password_md5 = md5.hexdigest()  # 调用hexdigest方法进行加密

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
    'Content-Type': 'application/json;charset=UTF-8'
    }
base_url = r'http://192.168.190.132:3000'
url = base_url + r'/jshERP-boot/user/login'

data = {'loginName': username, 'password': password_md5}
# cert_file = r'C:\Users\DELL\Desktop\1.crt'
resp = requests.post(url, json=data, headers=headers, verify=False, timeout=3)
print(resp.text)
token = resp.json()['data']['token']
print(token)

'''-----------------角色管理新增------------------'''
url_add = base_url + r'jshERP-boot/role/add'
# token_add = {'X-Access-Token': token}
headers['X-Access-Token'] = token
name = "采购专员"
type = "本机构数据"
description = "111"
data_character_add = {"name": name, "type": type, "description": description}
resp1 = requests.post(url_add, json=data_character_add, headers=headers, verify=False)
print(resp1.text)

'''-------------------------角色修改--------------------------'''
# url_update = base_url + r'/jshERP-boot/role/update'
# data_update = {
#   "deleteFlag": "0",
#   "description": "222",
#   "enabled": True,
#   "id": 10257,
#   "name": "采购主管",
#   "tenantId": 151172,
#   "type": "本机构数据"
# }
# resp2 = requests.put(url_update, json=data_update, headers=headers, verify=False)
# print(resp2.text)
'''-------------------------角色查询--------------------------'''
# name = '采购主管'
# description = ''
# url_search = base_url + r'/jshERP-boot/role/list'
# search_dict = {"name": name, "description": description}
# search_str = json.dumps(search_dict)
# data_search = {'search': search_str,
#                'column': 'createTime',
#                'order': 'desc',
#                'field': 'id,,,action,name,type,priceLimitStr,description,sort,enabled',
#                'currentPage': '1',
#                'pageSize': '10'
#                }
# resp3 = requests.get(url_search, params=data_search, headers=headers, verify=False)
# print(resp3.text)
'''-------------------------角色删除--------------------------'''
# url_delete = base_url + r'/jshERP-boot/role/delete'
# data_del = {'id': '10278'}
# resp4 = requests.delete(url_delete, params=data_del, headers=headers, verify=False)
# print(resp4.text)
'''-------------------------采购入库新增--------------------------'''
# url_buy = base_url + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# info_dict = {"organId": 135, "operTime": "2024-01-12 15:23:45", "number": "CGRK00000000926", "discount": 0, "discountMoney": 0, "discountLastMoney":1750,"otherMoney":0,"accountId":26,"changeAmount":-1750,"debt":0,"type":"入库","subType":"采购","defaultNumber":"CGRK00000000925","totalPrice":-1750,"accountIdList":"","accountMoneyList":"","fileName":"","status":"0"}
# rows_list = [{"id":"17050442255170144088","name":"至本洁面乳","standard":"标准版","model":None,"color":None,"materialOther":"","stock":20,"unit":"支","snList":"","batchNumber":"","expirationDate":"","sku":"","preNumber":"","finishNumber":"","operNumber":"50","unitPrice":35,"allPrice":1750,"taxRate":0,"taxMoney":0,"taxLastMoney":1750,"remark":"","linkId":"","orderNum":1,"depotId":"29","barCode":"1007"}]
# info_str = json.dumps(info_dict)
# rows_str = json.dumps(rows_list)
# data_buy = {"info": info_str,
#             "rows": rows_str}
# resp_buy = requests.post(url_buy, json=data_buy, headers=headers)
# print(resp_buy.text)

'''-------------------------采购入库修改--------------------------'''
# url_update = base_url + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# info_dict = {"id":1672,"type":"入库","subType":"采购","defaultNumber":"CGRK00000000926","number":"CGRK00000000926","createTime":"2024-01-12T07:48:47.000+0000","operTime":"2024-01-12 15:23:45","organId":135,"creator":134,"accountId":25,"changeAmount":-1575,"backAmount":0,"totalPrice":-1575,"payType":"现付","billType":None,"remark":None,"fileName":"","salesMan":None,"accountIdList":"","accountMoneyList":"","discount":0,"discountMoney":0,"discountLastMoney":1575,"otherMoney":0,"deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":None,"tenantId":134,"deleteFlag":"0","projectName":None,"organName":"至本合肥分公司","userName":None,"accountName":"金刚大萝莉","allocationProjectName":None,"materialsList":"至本洁面乳 标准版 ","salesManStr":None,"operTimeStr":"2024-01-12 15:23:45","finishDebt":None,"depotHeadType":"采购入库","creatorName":"yh","contacts":"小吴","telephone":"15627665687","address":None,"finishDeposit":None,"needDebt":None,"debt":0,"materialCount":None,"hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":None}
# rows_list = [{"id":"3235","name":"至本洁面乳","standard":"标准版","model":"","color":"","materialOther":"","stock":"100","unit":"支","snList":"","batchNumber":"","expirationDate":"","sku":"","preNumber":"35","finishNumber":"0","operNumber":"40","unitPrice":"35","allPrice":1575,"taxRate":"0","taxMoney":0,"taxLastMoney":1575,"remark":"","linkId":"","orderNum":1,"depotId":"29","barCode":"1007"}]
# info_str = json.dumps(info_dict)
# rows_str = json.dumps(rows_list)
# data_update = {"info": info_str,
#                "rows": rows_str
#                }
# resp_update = requests.put(url_update, json=data_update, headers=headers)
# print(resp_update.text)
'''-------------------------采购入库删除--------------------------'''
# url_del = base_url + r'/jshERP-boot/depotHead/delete'
# data_del = {"id": "1670"}
# resp_del = requests.delete(url_del, params=data_del, headers=headers, verify=False)
# print(resp_del.text)
'''-------------------------采购入库查询--------------------------'''
# url_search = base_url + r'/jshERP-boot/depotHead/list'
# search_dict = {"number":"","materialParam":"AKF","type":"入库","subType":"采购","roleType":"全部数据","organId":"","depotId":"","creator":"","linkNumber":"","accountId":"","hasDebt":"","status":"","remark":""}
# search_str = json.dumps(search_dict)
# data_search = {
#                 "search": search_str,
#                 "column": "createTime",
#                 "order": "desc",
#                 "field": "id,, action,organName,number,materialsList,operTimeStr,userName,materialCount,totalPrice,totalTaxLastMoney,needInMoney,changeAmount,debt,status",
#                 "currentPage": "1",
#                 "pageSize": "10"
# }
# resp_search = requests.get(url_search, params=data_search, headers=headers, verify=False)
# print(resp_search.text)
'''-------------------------供应商信息导入--------------------------'''
# url_import = base_url + r'/jshERP-boot/supplier/importVendor'
# files = {
#     'file': ('supplier.xls', open(r'supplier.xls', mode='rb'))
# }
# headers.pop('Content-Type')
# resp5 = requests.post(url_import, files=files, headers=headers, verify=False)
# print(resp5.text)
'''-------------------------零售出库新增--------------------------'''
# url_add = base_url + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# info_dict = {"organId":103,"operTime":"2024-01-14 16:32:22","number":"LSCK00000000927","payType":"现付","changeAmount":"500.00","getAmount":"500.00","backAmount":0,"accountId":26,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000926","totalPrice":500,"fileName":"","status":"0"}
# rows_list = [{"id":"17052211428940283970","name":"飘柔洗发水","standard":"小瓶装","model":None,"color":None,"materialOther":"","stock":19993,"unit":"瓶","snList":"","batchNumber":"","expirationDate":"","sku":"","operNumber":"50","unitPrice":10,"allPrice":500,"remark":"","orderNum":1,"depotId":"39","barCode":"1010"}]
# info_str = json.dumps(info_dict)
# rows_str = json.dumps(rows_list)
# data_add = {
#     'info': info_str,
#     'rows': rows_str
# }
# resp = requests.post(url_add, json=data_add, headers=headers, verify=False)
# print(resp.text)
'''-------------------------零售出库修改--------------------------'''
# url_update = base_url + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# info_dict = {"id":1674,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000927","number":"LSCK00000000927","createTime":"2024-01-14T08:42:40.000+0000","operTime":"2024-01-14 16:32:22","organId":103,"creator":134,"accountId":26,"changeAmount":"450.00","backAmount":0,"totalPrice":450,"payType":"现付","billType":None,"remark":None,"fileName":"","salesMan":None,"accountIdList":None,"accountMoneyList":None,"discount":None,"discountMoney":None,"discountLastMoney":0,"otherMoney":None,"deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":None,"tenantId":134,"deleteFlag":"0","projectName":None,"organName":"333333","userName":None,"accountName":"金刚大萝莉","allocationProjectName":None,"materialsList":"飘柔洗发水 小瓶装 ","salesManStr":None,"operTimeStr":"2024-01-14 16:32:22","finishDebt":None,"depotHeadType":"零售出库","creatorName":"yh","contacts":"老李","telephone":"13233567732","address":None,"finishDeposit":None,"needDebt":None,"debt":-500,"materialCount":None,"hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":None,"getAmount":"450.00"}
# rows_list = [{"id":"3243","name":"飘柔洗发水","standard":"小瓶装","model":"","color":"","materialOther":"","stock":"19895","unit":"瓶","snList":"","batchNumber":"","expirationDate":"","sku":"","operNumber":"40","unitPrice":"10","allPrice":450,"remark":"","orderNum":1,"depotId":"39","barCode":"1010"}]
# info_str = json.dumps(info_dict)
# rows_str = json.dumps(rows_list)
# data_update = {'info': info_str,
#                'rows': rows_str}
# resp = requests.put(url_update, json=data_update, headers=headers, verify=False)
# print(resp.text)
'''-------------------------零售出库删除--------------------------'''
# url_del = base_url + r'/jshERP-boot/depotHead/delete'
# data_del = {'id': '1631'}
# resp_del = requests.delete(url_del, params=data_del, headers=headers, verify=False)
# print(resp_del.text)
'''-------------------------零售出库查询--------------------------'''
# url_search = base_url + r'/jshERP-boot/depotHead/list'
# search_dict = {"number":"","materialParam":"飘柔","type":"出库","subType":"零售","roleType":"全部数据","organId":"","depotId":"","creator":"","accountId":"","status":"","remark":""}
# search_str = json.dumps(search_dict)
# data_search = {
#                 "search": search_str,
#                 "column": "createTime",
#                 "order": "desc",
#                 "field": "id,,action,organName,number,materialsList,operTimeStr,userName,materialCount,totalPrice,getAmount,backAmount,status",
#                 "currentPage": "1",
#                 "pageSize": "10"
# }
# resp_search = requests.get(url_search, params=data_search, headers=headers, verify=False)
# print(resp_search.text)
'''-------------------------零售退货新增--------------------------'''
# url_return_add = base_url + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# info_dict = {"operTime":"2024-01-14 18:27:20","number":"LSTH00000000930","changeAmount":-600,"getAmount":"600.00","backAmount":0,"accountId":26,"type":"入库","subType":"零售退货","defaultNumber":"LSTH00000000927","totalPrice":-600,"fileName":"","status":"0"}
# rows_list = [{"id":"17052280408330175606","name":"飘柔洗发水","standard":"小瓶装","model":None,"color":None,"materialOther":"","stock":19910,"unit":"瓶","snList":"","batchNumber":"","expirationDate":"","sku":"","preNumber":"","finishNumber":"","operNumber":"60","unitPrice":10,"allPrice":600,"remark":"","linkId":"","orderNum":1,"depotId":"39","barCode":"1010"}]
# info_str = json.dumps(info_dict)
# rows_str = json.dumps(rows_list)
# data_return_add = {
#     "info":info_str,
#     "rows":rows_str
# }
# resp_return_add = requests.post(url_return_add, json=data_return_add, headers=headers, verify=False)
# print(resp_return_add.text)
'''-------------------------零售退货修改--------------------------'''
# url_return_update = base_url + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# info_dict = {"id":1676,"type":"入库","subType":"零售退货","defaultNumber":"LSTH00000000928","number":"LSTH00000000928","createTime":"2024-01-14T12:06:56.000+0000","operTime":"2024-01-14 18:27:20","organId":None,"creator":134,"accountId":26,"changeAmount":-300,"backAmount":0,"totalPrice":-300,"payType":"现付","billType":None,"remark":None,"fileName":"","salesMan":None,"accountIdList":None,"accountMoneyList":None,"discount":None,"discountMoney":None,"discountLastMoney":0,"otherMoney":None,"deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":None,"tenantId":134,"deleteFlag":"0","projectName":None,"organName":None,"userName":None,"accountName":"金刚大萝莉","allocationProjectName":None,"materialsList":"飘柔洗发水 小瓶装 ","salesManStr":None,"operTimeStr":"2024-01-14 18:27:20","finishDebt":None,"depotHeadType":"零售退货入库","creatorName":"yh","contacts":None,"telephone":None,"address":None,"finishDeposit":None,"needDebt":None,"debt":-600,"materialCount":None,"hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":None,"getAmount":"300.00"}
# rows_list = [{"id":"3247","name":"飘柔洗发水","standard":"小瓶装","model":"","color":"","materialOther":"","stock":"20030","unit":"瓶","snList":"","batchNumber":"","expirationDate":"","sku":"","preNumber":"60","finishNumber":"0","operNumber":"30","unitPrice":"10","allPrice":300,"remark":"","linkId":"","orderNum":1,"depotId":"39","barCode":"1010"}]
# info_str = json.dumps(info_dict)
# rows_dict = json.dumps(rows_list)
# data_return_update = {
#                         "info": info_str,
#                         "rows": rows_dict
# }
# resp_return_update = requests.put(url_return_update, json=data_return_update, headers=headers, verify=False)
# print(resp_return_update.text)

'''-------------------------零售退货删除--------------------------'''
# url_return_del = base_url + r'/jshERP-boot/depotHead/delete'
# data_return_del = {'id': '1675'}
# resp_return_del = requests.delete(url_return_del, params=data_return_del, headers=headers, verify=False)
# print(resp_return_del.text)

'''-------------------------零售退货查询--------------------------'''
# url_return_search = base_url + r'/jshERP-boot/depotHead/list'
# data_search = {"number":"","materialParam":"飘柔","type":"入库","subType":"零售退货","roleType":"全部数据","organId":"","depotId":"","creator":"","linkNumber":"","accountId":"","status":"","remark":""}
# data_search_str = json.dumps(data_search)
# data_return_search = {"search": data_search_str,
#                       "column": "createTime",
#                       "order": "desc",
#                       "field": "id,,action,organName,number,materialsList,operTimeStr,userName,materialCount,totalPrice,getAmount,backAmount,status",
#                       "currentPage": "1",
#                       "pageSize": "10"}
# resp_return_search = requests.get(url_return_search, params=data_return_search, headers=headers, verify=False)
# print(resp_return_search.text)